const fKey = new function () {
    var prefBranch = null;
    var hotkeys = [];

    const handleShortcutKey = function(aEvent) {
        var curKeyCode = Number(aEvent.keyCode - aEvent.DOM_VK_F1);
        //dump("Key pressed --> " + curKeyCode);
        /* DOM_VK_F1 to DOM_VK_F12 */
        if (curKeyCode >= 0 && curKeyCode <= 11) {
            if(hotkeys[curKeyCode].value != undefined &&
                    hotkeys[curKeyCode].value != "") {
                //dump("\nvalue " + hotkeys[curKeyCode].value);
                //dump(gBrowser.currentURI.spec);
                /* if current tab is blank, open it here */
                if(gBrowser.currentURI.spec == "about:blank")
                    gBrowser.loadURI(hotkeys[curKeyCode].value);
                /* else, open a new tab */
                else
                    gBrowser.selectedTab = gBrowser.addTab(hotkeys[curKeyCode].value);
                aEvent.preventDefault();
                aEvent.stopPropagation();
            }
        }
    };

    const setKeyBinding = function() {

    };

    this.openSetting = function() {
        window.openDialog('chrome://fkeyshortcut/content/setting.xul', 'fKey-settingDialog', 'resizable, centerscreen, chrome', hotkeys);
    }

    this.init = function() {
        var prefSvc = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService);
        prefBranch = prefSvc.getBranch('fkeyshortcut.');
        hotkeys = eval(prefBranch.getCharPref('hotkey'));
        window.addEventListener('keypress', handleShortcutKey, true);
    };

}

window.addEventListener('load', function() {
        gBrowser.addEventListener("load", fKey.init, true);
        },
        false);

